/*   
 * Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * Founder. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with Founder.   
 *   
 */
package com.wujw.auto.utils;

/**   
 * 命名的处理（文件名，变量名）  
 * @author wujw  
 * @version   
 *       1.0, 2017年11月11日   
 */
public class NameUtil {
    /**
     * 处理文件名（一般根据表名）
     * @param tableName
     * @return  
     * @author wujw
     */
    public static String fileName(String tableName) {
        String fileName = "";
        //获取表名
        //如果有下划线，则将首字母都大写 如：USER_BASE ---> UserBase
        tableName = tableName.toLowerCase();
        if(tableName.contains("_")) { 
            String[] tNames = tableName.split("_");
            for (int i = 0; i < tNames.length; i++) {
                tNames[i] = tNames[i].substring(0, 1).toUpperCase()+tNames[i].substring(1);
                fileName += tNames[i]; 
            }
        }else {//首字母大写
            fileName = tableName.substring(0, 1).toUpperCase()+tableName.substring(1);
        } 
        return fileName;
    }
    
    public static void main(String[] args) {
        System.out.println(fileName("USSSSHS"));
        System.out.println(columnName("USERID"));
    }
    /**
     * 处理属性名
     * @param columnName
     * @return  
     * @author wujw
     */
    public static String columnName(String columnName) {
        //处理方式类似表明处理，如果存在"_" 将下划线后的单词首字母大写
        String properties = "";
        columnName = columnName.toLowerCase();
        if(columnName.contains("_")) {
            String[] colNames = columnName.split("_");
            for (int i = 0; i < colNames.length; i++) {
                for (int j = 1; j < colNames.length; j++) {
                   colNames[j] = colNames[j].substring(0, 1).toUpperCase()+colNames[j].substring(1); 
                }
                properties += colNames[i];
            }
        }else {
            properties = columnName;
        }
        return properties;
        
    }
}
